#define _CRT_SECURE_NO_WARNINGS	

int cmp(const void* x, const void* y)
{
    return *((int*)x) - *((int*)y);
}

int findLHS(int* nums, int numsSize)
{
    qsort(nums, numsSize, sizeof(int), cmp);
    int max, begin, end;
    max = begin = 0;
    end = 1;
    for (; end < numsSize; end++)
    {
        if (nums[end] - nums[begin] > 1)
            begin++;
        if (nums[end] - nums[begin] == 1)
            max = max > end - begin + 1 ? max : end - begin + 1;
    }
    return max;
}